cap log close
snapshot erase _all
clear all
estimates drop _all

*===========================*
*	Set Globals				*
*===========================*

	global filenum 32
	global filename "additional_figures"
	
*===========================*
*	Load In CPS		 File	*
*===========================*
	log using "${log_path}/${filenum}_${filename}.smcl", replace
	
	use "${data_path}/cps_00118.dta" , clear
	
	rename statefip state_fips
	
	merge m:1 state_fips using "${data_path}/statastates.dta", keep(1 3)

	label define mo 1 "Jan" 2 "Feb" 3 "Mar" 4 "Apr" 5 "May" 6 "Jun" 7 "Jul" 8 "Aug" 9 "Sept" 10 "Oct" 11 "Nov" 12 "Dec"
	label values month mo
	
*===========================*
*	Setup Analysis Vars		*
*===========================*

	keep if inrange(age,21,59) 
	
	drop if year==2020
	
	drop if asecflag==1
	
	*****************************
	*	Demog Variables			*
	*****************************
		
		gen female=(sex==2)
		
		gen childUnder18=(nchild>0)
		gen childUnder5=(nchlt5>0)
		
		gen childUnder12=(yngch<=12)
		
	*************************
	*	LFP Variables		*
	*************************
		gen inlf = (empstat<32)
		
		gen unemp = 	(empstat==21 | empstat==22)
			replace unemp=. if inlf==0
			
	*****************************
	*	Absence Variables		*
	*****************************
		
		gen absent_withJob=.
			replace absent_withJob=1 if absent>1						// Yes (laid off or other reason)	
			replace absent_withJob=0 if absent==0 & empstat==10			// at work
			replace absent_withJob=0 if absent==0 & empstat==1			// armed forces
			
		gen absent_yes =(absent==3)
		
			gen absent_vacation =	(whyabsnt==5)
			gen absent_sick = 		(whyabsnt==6)
			gen absent_family = 	(whyabsnt==7 | whyabsnt==8 | whyabsnt==9)
			gen absent_other = 		(whyabsnt>=10)		
			
		 gen absent_paid = (uh_absrea_b2>=1 & uh_absrea_b2<=10) |  (uh_absrea_b2>=21 & uh_absrea_b2<=30) 
		
			gen absent_paid_vacation = 	(uh_absrea_b2==1 | uh_absrea_b2==21) 
			gen absent_paid_sick = 		(uh_absrea_b2==2 | uh_absrea_b2==22) 
			gen absent_paid_family = 	(uh_absrea_b2>=3 & uh_absrea_b2<=5) |  (uh_absrea_b2>=23 & uh_absrea_b2<=25) 
			gen absent_paid_other =		(uh_absrea_b2>=6 & uh_absrea_b2<=10) |  (uh_absrea_b2>=26 & uh_absrea_b2<=30) 

		gen absent_unpaid = (uh_absrea_b2>=11 & uh_absrea_b2<=20) |  (uh_absrea_b2>=31 & uh_absrea_b2<=40) 
		
			gen absent_unpaid_vacation = 	(uh_absrea_b2==11 | uh_absrea_b2==31) 
			gen absent_unpaid_sick = 		(uh_absrea_b2==12 | uh_absrea_b2==32) 
			gen absent_unpaid_family = 		(uh_absrea_b2>=13 & uh_absrea_b2<=15) |  (uh_absrea_b2>=33 & uh_absrea_b2<=35) 
			gen absent_unpaid_other = 		(uh_absrea_b2>=16 & uh_absrea_b2<=20) |  (uh_absrea_b2>=36 & uh_absrea_b2<=40) 	

			
		*===========================*
		*	Telwork Variable 		*
		*	Based on occ2010ly		*
		*===========================*
					
			merge m:1 occ2010 using "${data_path}/census2010_tw.dta", nogen keep(1 3)
			
			*There are 48 Occupation codes that are left unassigned, I assign 47 of those manually. After merging the file, use the following code

			replace tw=	1	  if occ2010==		30
			replace tw=	1	  if occ2010==		130
			replace tw=	1	  if occ2010==		510
			replace tw=	1	  if occ2010==		520
			replace tw=	1	  if occ2010==		530
			replace tw=	0	  if occ2010==		560
			replace tw=	1	  if occ2010==		620
			replace tw=	0	  if occ2010==		720
			replace tw=	1	  if occ2010==		730
			replace tw=	1	  if occ2010==		1000
			replace tw=	1	  if occ2010==		1020
			replace tw=	1	  if occ2010==		1050
			replace tw=	1	  if occ2010==		1100
			replace tw=	1	  if occ2010==		1240
			replace tw=	1	  if occ2010==		1960
			replace tw=	1	  if occ2010==		2020
			replace tw=	1	  if occ2010==		2060
			replace tw=	1	  if occ2010==		2140
			replace tw=	1	  if occ2010==		2150
			replace tw=	1	  if occ2010==		2760
			replace tw=	1	  if occ2010==		2810
			replace tw=	0	  if occ2010==		3060
			replace tw=	0	  if occ2010==		3130
			replace tw=	1	  if occ2010==		3240
			replace tw=	0	  if occ2010==		3410
			replace tw=	0	  if occ2010==		3530
			replace tw=	0	  if occ2010==		3600
			replace tw=	0	  if occ2010==		3650
			replace tw=	1	  if occ2010==		3730
			replace tw=	1	  if occ2010==		3950
			replace tw=	0	  if occ2010==		4650
			replace tw=	1	  if occ2010==		4965
			replace tw=	0	  if occ2010==		5030
			replace tw=	1	  if occ2010==		5165
			replace tw=	1	  if occ2010==		5420
			replace tw=	1	  if occ2010==		5940
			replace tw=	0	  if occ2010==		7750
			replace tw=	0	  if occ2010==		7855
			replace tw=	0	  if occ2010==		7900
			replace tw=	0	  if occ2010==		8220
			replace tw=	0	  if occ2010==		8230
			replace tw=	0	  if occ2010==		8460
			replace tw=	0	  if occ2010==		8550
			replace tw=	1	  if occ2010==		9000
			replace tw=	0	  if occ2010==		9100
			replace tw=	0	  if occ2010==		9150
			replace tw=	0	  if occ2010==		9750	

			replace avtw=tw if tw!=. & avtw==.
			
			gen tw_binary=(tw>=0.5)
				replace tw_binary=. if tw==.	
				
		
keep if inlf==1 & unemp==0
		
snapshot save
*===========================*
*	Collapse Data			*
*===========================*


	*** All Data ***
		snapshot restore 1					
			collapse absent_paid [pw=wtfinl], by(month year)	

			gen datevar = ym(year, month)
			format datevar %tmMon_CCYY

			#delimit ;
			
				twoway 	connected absent_paid month if year==2010, lcolor(midgreen%50) mcolor(midgreen%50) ||
						connected absent_paid month if year==2011, lcolor(ltblue%50) mcolor(ltblue%50) ||
						connected absent_paid month if year==2012, lcolor(midgreen) mcolor(midgreen) ||				
						connected absent_paid month if year==2013, lcolor(ltblue) mcolor(ltblue) ||				
						connected absent_paid month if year==2014, lcolor(green%50) mcolor(green%50) ||				
						connected absent_paid month if year==2015, lcolor(blue%50) mcolor(blue%50) ||				
						connected absent_paid month if year==2016, lcolor(green) mcolor(green) ||				
						connected absent_paid month if year==2017, lcolor(blue) mcolor(blue) ||				
						connected absent_paid month if year==2018, lcolor(dkgreen) mcolor(dkgreen) ||				
						connected absent_paid month if year==2019, lcolor(dkblue) mcolor(dkblue) ,
							legend(
								label(1 "2010") label(2 "2011") label(3 "2012") label(4 "2013")
								label(5 "2014") label(6 "2015") label(7 "2016") label(8 "2017")
								label(9 "2018") label(10 "2019") 
							)
							ylabel(0(0.01)0.1)
							ytitle("Share Absent with Pay")
							xtitle("")
							xlabel(1(1)12, valuelabel);
						
			#delimit cr
						
			graph export "${out_path}/${filenum}_absent_paid_LR.png", replace	
			
	*** Female w Kids	****
				
		snapshot restore 1					
			keep if female==1 & childUnder12==1
			collapse absent_paid [pw=wtfinl], by(month year)	

			gen datevar = ym(year, month)
			format datevar %tmMon_CCYY

			#delimit ;
			
				twoway 	connected absent_paid month if year==2010, lcolor(midgreen%50) mcolor(midgreen%50) ||
						connected absent_paid month if year==2011, lcolor(ltblue%50) mcolor(ltblue%50) ||
						connected absent_paid month if year==2012, lcolor(midgreen) mcolor(midgreen) ||				
						connected absent_paid month if year==2013, lcolor(ltblue) mcolor(ltblue) ||				
						connected absent_paid month if year==2014, lcolor(green%50) mcolor(green%50) ||				
						connected absent_paid month if year==2015, lcolor(blue%50) mcolor(blue%50) ||				
						connected absent_paid month if year==2016, lcolor(green) mcolor(green) ||				
						connected absent_paid month if year==2017, lcolor(blue) mcolor(blue) ||				
						connected absent_paid month if year==2018, lcolor(dkgreen) mcolor(dkgreen) ||				
						connected absent_paid month if year==2019, lcolor(dkblue) mcolor(dkblue) ,
							legend(
								label(1 "2010") label(2 "2011") label(3 "2012") label(4 "2013")
								label(5 "2014") label(6 "2015") label(7 "2016") label(8 "2017")
								label(9 "2018") label(10 "2019") 
							)
							ylabel(0(0.01)0.10)
							ytitle("Share Absent with Pay")
							xtitle("")
							xlabel(1(1)12, valuelabel);
						
			#delimit cr
						
			graph export "${out_path}/${filenum}_absent_paid_LR_fem1_kid1.png", replace	
			
	*** Male 	****
				
		snapshot restore 1					
			keep if female==1 & childUnder12==0
			collapse absent_paid [pw=wtfinl], by(month year)	

			gen datevar = ym(year, month)
			format datevar %tmMon_CCYY

			#delimit ;
			
				twoway 	connected absent_paid month if year==2010, lcolor(midgreen%50) mcolor(midgreen%50) ||
						connected absent_paid month if year==2011, lcolor(ltblue%50) mcolor(ltblue%50) ||
						connected absent_paid month if year==2012, lcolor(midgreen) mcolor(midgreen) ||				
						connected absent_paid month if year==2013, lcolor(ltblue) mcolor(ltblue) ||				
						connected absent_paid month if year==2014, lcolor(green%50) mcolor(green%50) ||				
						connected absent_paid month if year==2015, lcolor(blue%50) mcolor(blue%50) ||				
						connected absent_paid month if year==2016, lcolor(green) mcolor(green) ||				
						connected absent_paid month if year==2017, lcolor(blue) mcolor(blue) ||				
						connected absent_paid month if year==2018, lcolor(dkgreen) mcolor(dkgreen) ||				
						connected absent_paid month if year==2019, lcolor(dkblue) mcolor(dkblue) ,
							legend(
								label(1 "2010") label(2 "2011") label(3 "2012") label(4 "2013")
								label(5 "2014") label(6 "2015") label(7 "2016") label(8 "2017")
								label(9 "2018") label(10 "2019") 
							)
							ylabel(0(0.01)0.1)
							ytitle("Share Absent with Pay")
							xtitle("")
							xlabel(1(1)12, valuelabel);
						
			#delimit cr
						
			graph export "${out_path}/${filenum}_absent_paid_LR_fem1_kid0.png", replace	
			
	*** Kids Under 12 	****
				
		snapshot restore 1					
			keep if female==0 & childUnder12==1
			collapse absent_paid [pw=wtfinl], by(month year)	

			gen datevar = ym(year, month)
			format datevar %tmMon_CCYY

			#delimit ;
			
				twoway 	connected absent_paid month if year==2010, lcolor(midgreen%50) mcolor(midgreen%50) ||
						connected absent_paid month if year==2011, lcolor(ltblue%50) mcolor(ltblue%50) ||
						connected absent_paid month if year==2012, lcolor(midgreen) mcolor(midgreen) ||				
						connected absent_paid month if year==2013, lcolor(ltblue) mcolor(ltblue) ||				
						connected absent_paid month if year==2014, lcolor(green%50) mcolor(green%50) ||				
						connected absent_paid month if year==2015, lcolor(blue%50) mcolor(blue%50) ||				
						connected absent_paid month if year==2016, lcolor(green) mcolor(green) ||				
						connected absent_paid month if year==2017, lcolor(blue) mcolor(blue) ||				
						connected absent_paid month if year==2018, lcolor(dkgreen) mcolor(dkgreen) ||				
						connected absent_paid month if year==2019, lcolor(dkblue) mcolor(dkblue) ,
							legend(
								label(1 "2010") label(2 "2011") label(3 "2012") label(4 "2013")
								label(5 "2014") label(6 "2015") label(7 "2016") label(8 "2017")
								label(9 "2018") label(10 "2019") 
							)
							ylabel(0(0.01)0.1)
							ytitle("Share Absent with Pay")
							xtitle("")
							xlabel(1(1)12, valuelabel);
						
			#delimit cr
						
			graph export "${out_path}/${filenum}_absent_paid_LR_fem0_kid1.png", replace				
			
			
	*** No Kids Under 12 	****
				
		snapshot restore 1					
			keep if female==0 & childUnder12==0
			collapse absent_paid [pw=wtfinl], by(month year)	

			gen datevar = ym(year, month)
			format datevar %tmMon_CCYY

			#delimit ;
			
				twoway 	connected absent_paid month if year==2010, lcolor(midgreen%50) mcolor(midgreen%50) ||
						connected absent_paid month if year==2011, lcolor(ltblue%50) mcolor(ltblue%50) ||
						connected absent_paid month if year==2012, lcolor(midgreen) mcolor(midgreen) ||				
						connected absent_paid month if year==2013, lcolor(ltblue) mcolor(ltblue) ||				
						connected absent_paid month if year==2014, lcolor(green%50) mcolor(green%50) ||				
						connected absent_paid month if year==2015, lcolor(blue%50) mcolor(blue%50) ||				
						connected absent_paid month if year==2016, lcolor(green) mcolor(green) ||				
						connected absent_paid month if year==2017, lcolor(blue) mcolor(blue) ||				
						connected absent_paid month if year==2018, lcolor(dkgreen) mcolor(dkgreen) ||				
						connected absent_paid month if year==2019, lcolor(dkblue) mcolor(dkblue) ,
							legend(
								label(1 "2010") label(2 "2011") label(3 "2012") label(4 "2013")
								label(5 "2014") label(6 "2015") label(7 "2016") label(8 "2017")
								label(9 "2018") label(10 "2019") 
							)
							ylabel(0(0.01)0.1)
							ytitle("Share Absent with Pay")
							xtitle("")
							xlabel(1(1)12, valuelabel);
						
			#delimit cr
						
			graph export "${out_path}/${filenum}_absent_paid_LR_fem0_kid0.png", replace				
	
*** No Telework 	****
				
		snapshot restore 1					
			keep if tw_binary==0
			collapse absent_paid [pw=wtfinl], by(month year)	

			gen datevar = ym(year, month)
			format datevar %tmMon_CCYY

			#delimit ;
			
				twoway 	connected absent_paid month if year==2010, lcolor(midgreen%50) mcolor(midgreen%50) ||
						connected absent_paid month if year==2011, lcolor(ltblue%50) mcolor(ltblue%50) ||
						connected absent_paid month if year==2012, lcolor(midgreen) mcolor(midgreen) ||				
						connected absent_paid month if year==2013, lcolor(ltblue) mcolor(ltblue) ||				
						connected absent_paid month if year==2014, lcolor(green%50) mcolor(green%50) ||				
						connected absent_paid month if year==2015, lcolor(blue%50) mcolor(blue%50) ||				
						connected absent_paid month if year==2016, lcolor(green) mcolor(green) ||				
						connected absent_paid month if year==2017, lcolor(blue) mcolor(blue) ||				
						connected absent_paid month if year==2018, lcolor(dkgreen) mcolor(dkgreen) ||				
						connected absent_paid month if year==2019, lcolor(dkblue) mcolor(dkblue) ,
							legend(
								label(1 "2010") label(2 "2011") label(3 "2012") label(4 "2013")
								label(5 "2014") label(6 "2015") label(7 "2016") label(8 "2017")
								label(9 "2018") label(10 "2019") 
							)
							ylabel(0(0.01)0.1)
							ytitle("Share Absent with Pay")
							xtitle("")
							xlabel(1(1)12, valuelabel);
						
			#delimit cr
						
			graph export "${out_path}/${filenum}_absent_paid_LR_tw0.png", replace	
			
***  Telework 	****
				
		snapshot restore 1					
			keep if tw_binary==1
			collapse absent_paid [pw=wtfinl], by(month year)	

			gen datevar = ym(year, month)
			format datevar %tmMon_CCYY

			#delimit ;
			
				twoway 	connected absent_paid month if year==2010, lcolor(midgreen%50) mcolor(midgreen%50) ||
						connected absent_paid month if year==2011, lcolor(ltblue%50) mcolor(ltblue%50) ||
						connected absent_paid month if year==2012, lcolor(midgreen) mcolor(midgreen) ||				
						connected absent_paid month if year==2013, lcolor(ltblue) mcolor(ltblue) ||				
						connected absent_paid month if year==2014, lcolor(green%50) mcolor(green%50) ||				
						connected absent_paid month if year==2015, lcolor(blue%50) mcolor(blue%50) ||				
						connected absent_paid month if year==2016, lcolor(green) mcolor(green) ||				
						connected absent_paid month if year==2017, lcolor(blue) mcolor(blue) ||				
						connected absent_paid month if year==2018, lcolor(dkgreen) mcolor(dkgreen) ||				
						connected absent_paid month if year==2019, lcolor(dkblue) mcolor(dkblue) ,
							legend(
								label(1 "2010") label(2 "2011") label(3 "2012") label(4 "2013")
								label(5 "2014") label(6 "2015") label(7 "2016") label(8 "2017")
								label(9 "2018") label(10 "2019") 
							)
							ylabel(0(0.01)0.1)
							ytitle("Share Absent with Pay")
							xtitle("")
							xlabel(1(1)12, valuelabel);
						
			#delimit cr
						
			graph export "${out_path}/${filenum}_absent_paid_LR_tw1.png", replace	
			
	
*** No Children 	****
				
		snapshot restore 1					
			keep if childUnder12==0
			collapse absent_paid [pw=wtfinl], by(month year)	

			gen datevar = ym(year, month)
			format datevar %tmMon_CCYY

			#delimit ;
			
				twoway 	connected absent_paid month if year==2010, lcolor(midgreen%50) mcolor(midgreen%50) ||
						connected absent_paid month if year==2011, lcolor(ltblue%50) mcolor(ltblue%50) ||
						connected absent_paid month if year==2012, lcolor(midgreen) mcolor(midgreen) ||				
						connected absent_paid month if year==2013, lcolor(ltblue) mcolor(ltblue) ||				
						connected absent_paid month if year==2014, lcolor(green%50) mcolor(green%50) ||				
						connected absent_paid month if year==2015, lcolor(blue%50) mcolor(blue%50) ||				
						connected absent_paid month if year==2016, lcolor(green) mcolor(green) ||				
						connected absent_paid month if year==2017, lcolor(blue) mcolor(blue) ||				
						connected absent_paid month if year==2018, lcolor(dkgreen) mcolor(dkgreen) ||				
						connected absent_paid month if year==2019, lcolor(dkblue) mcolor(dkblue) ,
							legend(
								label(1 "2010") label(2 "2011") label(3 "2012") label(4 "2013")
								label(5 "2014") label(6 "2015") label(7 "2016") label(8 "2017")
								label(9 "2018") label(10 "2019") 
							)
							ylabel(0(0.01)0.1)
							ytitle("Share Absent with Pay")
							xtitle("")
							xlabel(1(1)12, valuelabel);
						
			#delimit cr
						
			graph export "${out_path}/${filenum}_absent_paid_LR_kids0.png", replace	
			
***  Children 	****
				
		snapshot restore 1					
			keep if childUnder12==1
			collapse absent_paid [pw=wtfinl], by(month year)	

			gen datevar = ym(year, month)
			format datevar %tmMon_CCYY

			#delimit ;
			
				twoway 	connected absent_paid month if year==2010, lcolor(midgreen%50) mcolor(midgreen%50) ||
						connected absent_paid month if year==2011, lcolor(ltblue%50) mcolor(ltblue%50) ||
						connected absent_paid month if year==2012, lcolor(midgreen) mcolor(midgreen) ||				
						connected absent_paid month if year==2013, lcolor(ltblue) mcolor(ltblue) ||				
						connected absent_paid month if year==2014, lcolor(green%50) mcolor(green%50) ||				
						connected absent_paid month if year==2015, lcolor(blue%50) mcolor(blue%50) ||				
						connected absent_paid month if year==2016, lcolor(green) mcolor(green) ||				
						connected absent_paid month if year==2017, lcolor(blue) mcolor(blue) ||				
						connected absent_paid month if year==2018, lcolor(dkgreen) mcolor(dkgreen) ||				
						connected absent_paid month if year==2019, lcolor(dkblue) mcolor(dkblue) ,
							legend(
								label(1 "2010") label(2 "2011") label(3 "2012") label(4 "2013")
								label(5 "2014") label(6 "2015") label(7 "2016") label(8 "2017")
								label(9 "2018") label(10 "2019") 
							)
							ylabel(0(0.01)0.1)
							ytitle("Share Absent with Pay")
							xtitle("")
							xlabel(1(1)12, valuelabel);
						
			#delimit cr
						
			graph export "${out_path}/${filenum}_absent_paid_LR_kids1.png", replace				
		